package com.fanghuaiming.seata.account.service.impl;

import com.fanghuaiming.seata.account.dao.mapper.SeataTccAccountMapper;
import com.fanghuaiming.seata.account.service.AccountService;
import com.fanghuaiming.seata.account.tcc.SeataPhaseTccAccount;
import io.seata.spring.annotation.GlobalTransactional;
import java.math.BigDecimal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/****
 * @description: 账户服务接口实现类
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2020/11/27 下午1:59
 *
 */
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    /**
     * 账户mapper
     */
    @Autowired
    private SeataTccAccountMapper seataTccAccountMapper;

    @Autowired
    private SeataPhaseTccAccount seataPhaseTccAccount;


    /**
     * @Description: 扣减账户余额
     *
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/30 下午6:07
     * @version:1.0.0
     */
    @GlobalTransactional
    @Override
    public void decrease(Long userId, BigDecimal money) {
        //accountMapper.decrease(userId,money);
        //调用TCC 第一阶段的方法
        seataPhaseTccAccount.prepareDecreaseAccount(null,userId,money);
    }
}
